package day5;

import java.util.Scanner;

import org.junit.Test;

public class Demo {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学生的数量：");
		int count = scanner.nextInt();
		// int[] array = new int[count];
		Student[] students = new Student[count];
		for (int i = 1; i < students.length; i++) {
			System.out.println("请输入id：");
			int id = scanner.nextInt();
			System.out.println("请输入名字：");
			String name = scanner.next();
			System.out.println("请输入年龄：");
			int age = scanner.nextInt();
			System.out.println("请输入班级名字：");
			String className = scanner.next();
			
			// 每次循环构造一个Student对象
			Student student = new Student(id, name, age, className);
			// 把构造的学生对象放到指定下标位置
			students[i] = student;
		}
		
		System.out.println("-----------------------");
		for (int i = 0; i < students.length; i++) {
			Student student = students[i];
			// System.out.println(student.toString());
			System.out.println(student);
		}
		System.out.println("-----------------------");
		
		while (true) {
			System.out.println("根据id查找输入：1");
			System.out.println("根据name查找输入：2");
			System.out.println("根据age查找输入：3");
			System.out.println("根据className查找输入：4");
			System.out.println("退出：0");
			int type = scanner.nextInt();
			if (type == 0) {
				System.out.println("退出搜索");
				break;
			}
			
			switch (type) {
			case 1: // 根据id查找
				System.out.println("请输入要查找的学生id：");
				int id = scanner.nextInt();
				// 根据id查找到了没有
				// boolean isExistId = false;
				boolean isSearchByIdFind = false;
				for (int i = 0; i < students.length; i++) {
					Student student = students[i];
					if (student.getId() == id) {
						isSearchByIdFind = true;
						System.out.println(student);
					}
				}
				// 如果遍历完了还是false，证明没有该信息学生
				if (isSearchByIdFind == false) {
					System.out.println("没有该信息的学生");
				}
				break;
			case 2: // 根据name查找
				System.out.println("请输入要查找的名字：");
				String name = scanner.next();
				boolean isSearchByNameFind = false;
				for (int i = 0; i < students.length; i++) {
					Student student = students[i];
					// 判断字符串的内容是不是相等，不能用==，要是用equals()方法
					if (name.equals(student.getName())) {
						isSearchByNameFind = true;
						System.out.println(student);
					}
				}
				if (isSearchByNameFind == false) {
					System.out.println("没有该信息的学生");
				}
				break;
			case 3: // 根据age查找
				System.out.println("请输入要查找的学生age：");
				int age = scanner.nextInt();
				// 根据age查找到了没有
				boolean isSearchByAgeFind = false;
				for (int i = 0; i < students.length; i++) {
					Student student = students[i];
					if (student.getAge() == age) {
						isSearchByAgeFind = true;
						System.out.println(student);
					}
				}
				// 如果遍历完了还是false，证明没有该信息学生
				if (isSearchByAgeFind == false) {
					System.out.println("没有该信息的学生");
				}
				break;
			case 4: // 根据classNmae查找
				System.out.println("4");
				break;
			default:
				break;
			}
			
		}
		
		
	}
	

	@Test
	public void test1() {
		// new 调用的是构造方法
		// The constructor Student() is undefined
		Student student1 = new Student();
		student1.setId(1);
		student1.setAge(23);
		
		Student student2 = new Student(2, "lisi", 23, "UI");
		System.out.println(student2);
	}
	
	@Test
	public void test444() {
		Student student = new Student(1, "王五", 23, "Java1912");
		student.show();
		//student.study();
		//System.out.println(student.toString());
		//System.out.println(student);
	}
	
	void show(int a, char b, double c){}
	// Duplicate method show(int, char, double) in type Demo
	// void show(int x, char y, double z){}
	
	// This method must return a result of type int
	int show(int a, double c, char b){
		return 0;
	} 
	
	
	
	
}
